package com.lanju.app.service;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dxl.common.model.Page;
import com.dxl.common.utils.Utils;
import com.dxl.lanju.dao.ShopDao;
import com.lanju.app.message.bean.B101Request;
import com.lanju.app.message.bean.B101Response;
import com.lanju.app.message.bean.B101Response.ShopBean;
import com.lanju.app.util.AppUtil;
import com.lanju.entity.Shop;
import com.lanju.entity.User;

/**
 * 获取门店列表
 * @author fly
 *
 */
@Service("B101Service")
public class B101Service extends BaseService<B101Request,B101Response>{
	

	@Autowired
	protected  ShopDao dao;
	
	@Override
	public B101Response doService(B101Request r, User u) throws Exception {
		B101Response res = new B101Response();
		List<Shop> shops = null;
		if(Utils.isNotNull(r.getPageSize()) && r.getPageSize()!=0){
			Page<Shop> page = dao.list(r.getKey(), null, null, null, r.getPageNo(), r.getPageSize());
			shops = page.getRows();
			res.setPageCount(page.getPageCount());
		}else{
			shops = dao.list(r.getKey(), null, null, null);
		}
		List<ShopBean> list = new ArrayList<>();
		for(Shop shop : shops){
			ShopBean bean = new ShopBean();
			BeanUtils.copyProperties(shop, bean);
			bean.setPath(StringUtils.isBlank(shop.getPath())?"":(AppUtil.oss_psth+shop.getPath()));
			bean.setPathSl(StringUtils.isBlank(shop.getPath())?"":(bean.getPath()+AppUtil.oss_bucket_thumb150x150));
			list.add(bean);
		}
		res.setShops(list);
		res.setSuccess(true);
		return res;	
	}
}
